<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:available:add']"
        >新增</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center" min-width="5%"/>
      <el-table-column label="费用名称" align="center" prop="name" key="name"/>
      <el-table-column label="费用类型" align="center" prop="type" key="type"/>
      <el-table-column label="子类型" align="center" prop="subType" key="subType"/>
      <el-table-column label="费用" align="center" prop="feeConfig" key="feeConfig"/>
      <el-table-column label="单位" align="center" prop="unit" key="unit"/>
      <el-table-column label="备注" align="center" prop="remark" key="remark"/>
      <el-table-column label="状态" align="center" prop="status" key="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fee_thali_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="startAt">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startAt) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endAt">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endAt) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="费用名称:" prop="name">
          <el-input v-model="form.name" placeholder="请输入费用名称" maxlength="50" />
        </el-form-item>
        <el-form-item label="类型:" prop="type">
          <el-input v-model="form.type" placeholder="请输入费用类型" maxlength="50" />
        </el-form-item>
        <el-form-item label="子类型:" prop="subType">
          <el-input v-model="form.subType" placeholder="请输入子类型" maxlength="50" />
        </el-form-item>
        <el-form-item label="费用:" prop="feeConfig">
          <el-input v-model="form.feeConfig" type="number" :min="0" placeholder="请设置费用配置"/>
        </el-form-item>
        <el-form-item label="单位:" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" maxlength="50" />
        </el-form-item>
        <el-form-item label="备注:" prop="remark">
          <el-input type="textarea" :rows="3" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="submitForm">确 定</el-button>
        <el-button size="mini" @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { availablePageList,addFeeThali } from '@/api/triones/feeThali'
export default {
  name: "index",
  dicts: ['fee_thali_status'],
  data() {
    return {
      loading: false,
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      dataList: [],
      total: 0,
      detailOpen: false,
      detail:{},
      dateRange: [],
      title: '',
      open: false,
      form: {},
      rules: {
        name: [
          { required: true, message: "费用名称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "费用类型不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList () {
      this.loading = true;
      this.addDateRange(this.queryParams, this.dateRange.map(time => time / 1000));
      availablePageList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 检索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增 */
    handleAdd() {
      this.reset();
      this.title = '费用费用新增';
      this.open = true;
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        type: undefined,
        subType: undefined,
        feeConfig: undefined,
        unit: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 提交 */
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.form.id !== undefined) {

          } else {
            addFeeThali(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 子类型更改 */
    typeChange() {
      console.log('子类型更改')
      this.form.subType = undefined;
    }
  }
}
</script>
<style scoped lang="scss">

</style>
